package edu.ccut.saturn.studio.component.part;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.ide.IDE;

import edu.ccut.saturn.studio.component.common.CommonSet;
import edu.ccut.saturn.studio.component.dialog.AddParamDialog;
import edu.ccut.saturn.studio.component.dialog.CreateClassDialog;
import edu.ccut.saturn.studio.component.dialog.EditParamDialog;
import edu.ccut.saturn.studio.component.editor.ComponentFileEditor;
import edu.ccut.saturn.studio.component.model.Component;
import edu.ccut.saturn.studio.component.model.ComponentModel;
import edu.ccut.saturn.studio.component.model.Parameter;
import edu.ccut.saturn.studio.core.search.SaturnFileSearcher;
import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnProjectUtil;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnSWTUtils;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnSectionPart;

public class ComponentPagePart extends SaturnSectionPart {

	private Text descriptionText;
	private Combo loadstartcombo;
	private Text nameText;
	private Text keyText;
	private Text classText;
	private ComponentFileEditor editor;
	public  TableViewer paramTableViewer;
	private Table paramTable;
	private ComponentModel componentModel;
	private Shell shell;
	private Component component;
	private IProject project = null;

	public ComponentPagePart(Composite parent, IManagedForm form,
			ComponentFileEditor editor) {
		super(parent, form);
		
		this.editor = editor;
		this.shell = form.getForm().getShell();
		this.project = SaturnProjectUtil.getProject(editor.getEditorInput());
		this.componentModel = editor.getComponentModel();
		this.component = this.componentModel.getComponent();
		
		getSection().setClient(createClient(form));
	}
	
	
	public void dispose() {
	}
	
	protected String getSectionDescription() {
		return Messages.getString("ComponentFilePropertiesPart.installproperty"); //$NON-NLS-1$
	}

	protected String getSectionTitle() {
		return Messages.getString("ComponentFilePropertiesPart.property"); //$NON-NLS-1$
	}

	private Control createClient(IManagedForm form) {
		FormToolkit toolkit = form.getToolkit();
		Composite composite = new Composite(getSection(), SWT.NULL);

		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 4;
		composite.setLayout(gridLayout);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		final Label label = new Label(composite, SWT.NONE);
		label.setLayoutData(new GridData());
		toolkit.adapt(label, true, true);
		label.setText(Messages.getString("ComponentPagePart.key")); //$NON-NLS-1$

		keyText = new Text(composite, SWT.BORDER);
		keyText.setEditable(false);
		toolkit.adapt(keyText, true, true);
		final GridData gd_keyText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		gd_keyText.widthHint = 373;
		keyText.setLayoutData(gd_keyText);
		new Label(composite, SWT.NONE);


		final Label label_1 = new Label(composite, SWT.NONE);
		toolkit.adapt(label_1, true, true);
		label_1.setText(Messages.getString("ComponentPagePart.name")); //$NON-NLS-1$

		nameText = new Text(composite, SWT.BORDER);
		nameText.setEditable(false);
		toolkit.adapt(nameText, true, true);
		final GridData gridDataText2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		gridDataText2.widthHint = 246;
		nameText.setLayoutData(gridDataText2);
		new Label(composite, SWT.NONE);
		
		Hyperlink link = toolkit.createHyperlink(composite, Messages
				.getString("ComponentFilePropertiesPart.component"), SWT.WRAP); //$NON-NLS-1$
		link.setLayoutData(new GridData());
		link.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				if (project != null) {
					IFile classFile;
					List<String> srcList = new ArrayList<String>();
					srcList = SaturnFileSearcher.getClasspathInfo(project, "src"); //$NON-NLS-1$

//					srcList = ParseClasspath.getClasspathInfo(project, "src"); //$NON-NLS-1$
					if (srcList != null && srcList.size() != 0) {
						for (int i = 0; i < srcList.size(); i++) {
							String srcName = srcList.get(i);
							classFile = (IFile) project.findMember("\\" //$NON-NLS-1$
									+ srcName + "\\" + classText.getText().replace(".", "\\") + ".java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
							if (classFile != null && classFile.exists()) {
								openEditor(classFile);
							}
						}
					}
				}
			}
		});

		classText = new Text(composite, SWT.READ_ONLY | SWT.BORDER);
		toolkit.adapt(classText, true, true);
		final GridData gridDataText1 = new GridData(SWT.FILL, SWT.CENTER, true, false);
		classText.setLayoutData(gridDataText1);

		final Button browerButton = new Button(composite, SWT.NONE);
		browerButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				IJavaSearchScope searchScope = SearchEngine
						.createWorkspaceScope();
				TypeSelectionDialog2 dialog = new TypeSelectionDialog2(null,
						false, new ProgressMonitorDialog(null), searchScope,
						IJavaSearchConstants.TYPE);
				dialog.setMessage(Messages
						.getString("ComponentFilePropertiesPart.pleasechooseclass")); //$NON-NLS-1$
				dialog.setBlockOnOpen(true);
				dialog.setTitle(Messages
						.getString("ComponentFilePropertiesPart.chooseclass")); //$NON-NLS-1$
				if (Dialog.OK == dialog.open()) {
					IType obj = (IType) dialog.getFirstResult();
					classText.setText(obj.getFullyQualifiedName());
					componentModel.updateComponentAttribute(ComponentModel.COMPONENT_ATTRIBUTE_CLASS, classText.getText().trim());
				}
			}
		});
		toolkit.adapt(browerButton, true, true);
		browerButton.setText(Messages.getString("ComponentPagePart.browse")); //$NON-NLS-1$

		final Button createClassButton = new Button(composite, SWT.NONE);
		final GridData buttonG = new GridData(SWT.CENTER, SWT.CENTER, false, false);
		buttonG.widthHint = 60;
		createClassButton.setLayoutData(buttonG);
		toolkit.adapt(createClassButton, true, true);
		createClassButton.setText(Messages.getString("ComponentPagePart.create")); //$NON-NLS-1$
		createClassButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				CreateClassDialog classDialog = new CreateClassDialog(
						getSection().getShell(), project, ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				if (classDialog.open() == IDialogConstants.OK_ID) {
					classText.setText(classDialog.getPkgName()
							+ "." + classDialog.getClassName()); //$NON-NLS-1$
					componentModel.updateComponentAttribute(ComponentModel.COMPONENT_ATTRIBUTE_CLASS, classText.getText().trim());
				}
			}
		});

		final Label label_2 = new Label(composite, SWT.NONE);
		toolkit.adapt(label_2, true, true);
		label_2.setText(Messages.getString("ComponentPagePart.loadstart")); //$NON-NLS-1$

		loadstartcombo = new Combo(composite, SWT.NONE);
		loadstartcombo.setItems(new String[] {"false", "true"});
		loadstartcombo.setText("false");
		toolkit.adapt(loadstartcombo, true, true);
		final GridData gd_combo_1 = new GridData(SWT.FILL, SWT.CENTER, true, false);
		loadstartcombo.setLayoutData(gd_combo_1);
		loadstartcombo.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				String load = loadstartcombo.getText();
				component.setLoadStart(load);
				
				componentModel.updateComponentLoadStart(load);
			}
		});
		
		new Label(composite, SWT.NONE);
		new Label(composite, SWT.NONE);

		final Label label_3 = new Label(composite, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
		toolkit.adapt(label_3, true, true);
		label_3.setText(Messages.getString("ComponentPagePart.description")); //$NON-NLS-1$

		descriptionText = new Text(composite, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
		descriptionText.setTextLimit(200);
		toolkit.adapt(descriptionText, true, true);
		final GridData gd_DesValText = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
		gd_DesValText.widthHint = 73;
		gd_DesValText.heightHint = 50;
		descriptionText.setLayoutData(gd_DesValText);
		descriptionText.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				String description = descriptionText.getText();
				component.setDescription(description);
				
				componentModel.updateComponentDescription(description);
			}
		});
		new Label(composite, SWT.NONE);

		final Label label_4 = new Label(composite, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
		toolkit.adapt(label_4, true, true);
		label_4.setText(Messages.getString("ComponentPagePart.parameter")); //$NON-NLS-1$

		paramTableViewer = new TableViewer(composite, SWT.BORDER
				| SWT.FULL_SELECTION);
		paramTable = paramTableViewer.getTable();
		paramTable.setLinesVisible(true);
		paramTable.setHeaderVisible(true);
		GridData gridDataTable = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
		paramTable.setLayoutData(gridDataTable);

		final TableColumn newColumnTableColumn0 = new TableColumn(paramTable,
				SWT.NONE);
		newColumnTableColumn0.setWidth(40);
		newColumnTableColumn0.setText(Messages
				.getString("ComponentFilePropertiesPart.sequenceid")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn = new TableColumn(paramTable,
				SWT.NONE);
		newColumnTableColumn.setWidth(70);
		newColumnTableColumn.setText(Messages
				.getString("ComponentFilePropertiesPart.name1")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_1 = new TableColumn(paramTable,
				SWT.NONE);
		newColumnTableColumn_1.setWidth(110);
		newColumnTableColumn_1.setText(Messages
				.getString("ComponentFilePropertiesPart.type")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_2 = new TableColumn(paramTable,
				SWT.NONE);
		newColumnTableColumn_2.setWidth(80);
		newColumnTableColumn_2.setText(Messages
				.getString("ComponentFilePropertiesPart.inputoroutput")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_3 = new TableColumn(paramTable,
				SWT.NONE);
		newColumnTableColumn_3.setWidth(60);
		newColumnTableColumn_3.setText(Messages
				.getString("ComponentFilePropertiesPart.expression")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_4 = new TableColumn(paramTable,
				SWT.NONE);
		newColumnTableColumn_4.setWidth(80);
		newColumnTableColumn_4.setText(Messages
				.getString("ComponentFilePropertiesPart.dataset")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_5 = new TableColumn(paramTable,
				SWT.NONE);
		newColumnTableColumn_5.setWidth(120);
		newColumnTableColumn_5.setText(Messages
				.getString("ComponentFilePropertiesPart.description1")); //$NON-NLS-1$

		paramTableViewer.setContentProvider(new SaturnSWTUtils.SaturnTableViewerDefaultContentProvider());
		paramTableViewer.setLabelProvider(new SaturnSWTUtils.SaturnTableViewerDefaultLabelProvider() {
			public String getColumnText(Object element, int columnIndex) {
				Parameter parameterVO = (Parameter)element;
				if (columnIndex == 0) {
					return String.valueOf(parameterVO.getId());
				}
				if (columnIndex == 1) {
					return parameterVO.getName();
				}
				if (columnIndex == 2) {
					return parameterVO.getClassStr();
				}
				if (columnIndex == 3) {
					return CommonSet.reverseConvert(parameterVO.getPassingType());
				}
				if (columnIndex == 4) {
					return parameterVO.getValueKey();
				}
				if (columnIndex == 5) {
					return CommonSet.reverseConvert(parameterVO.getScope() + ""); //$NON-NLS-1$
				}
				if (columnIndex == 6) {
					return parameterVO.getDescription();
				}
					
				return ""; //$NON-NLS-1$
			}
		});

		modifyParameter();

		adaptRecursively(toolkit, composite);

		final Composite buttonGroup = new Composite(composite, SWT.NONE);
		final GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, false, false);
		buttonGroup.setLayoutData(gridData2);
		buttonGroup.setLayout(new GridLayout());
		toolkit.adapt(buttonGroup);

		final Button addButton = new Button(buttonGroup, SWT.NONE);
		final GridData gd_addButton = new GridData(SWT.FILL, SWT.CENTER, false, false);
		gd_addButton.widthHint = 60;
		addButton.setLayoutData(gd_addButton);
		toolkit.adapt(addButton, true, true);
		addButton.setText(Messages.getString("ComponentPagePart.add")); //$NON-NLS-1$
		addButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doAdd();
			}
		});

		final Button editButton = new Button(buttonGroup, SWT.NONE);
		editButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		toolkit.adapt(editButton, true, true);
		editButton.setText(Messages.getString("ComponentPagePart.edit")); //$NON-NLS-1$
		editButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doEdit();
			}
		});

		final Button delButton = new Button(buttonGroup, SWT.NONE);
		delButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		toolkit.adapt(delButton, true, true);
		delButton.setText(Messages.getString("ComponentPagePart.delete")); //$NON-NLS-1$
		delButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doRemove();
			}
		});

		final Button upButton = new Button(buttonGroup, SWT.NONE);
		upButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		toolkit.adapt(upButton, true, true);
		upButton.setText(Messages.getString("ComponentPagePart.upshift")); //$NON-NLS-1$
		upButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doUp();
			}
		});

		final Button downButton = new Button(buttonGroup, SWT.NONE);
		downButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		toolkit.adapt(downButton, true, true);
		downButton.setText(Messages.getString("ComponentPagePart.downshift")); //$NON-NLS-1$
		downButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doDown();
			}
		});

		this.inital();
		
		return composite;
	}

	private void openEditor(final IFile file) {
		if (file != null) {
			shell.getDisplay().asyncExec(new Runnable() {
				public void run() {
					try {
						IWorkbenchPage page = PlatformUI.getWorkbench()
								.getActiveWorkbenchWindow().getActivePage();
						IDE.setDefaultEditor(file,
								"org.eclipse.jdt.ui.CompilationUnitEdito"); //$NON-NLS-1$
						IDE.openEditor(page, file, true);
					} catch (PartInitException e) {

					}
				}
			});
		}
	}


	protected void modifyParameter() {
		// 建立一个表格单元编辑器
		CellEditor[] editors = new CellEditor[7];
		editors[0] = null;
		editors[1] = new TextCellEditor(paramTable);
		editors[2] = new ComboBoxCellEditor(paramTable, CommonSet.classTypes,
				SWT.READ_ONLY);
		editors[3] = new ComboBoxCellEditor(paramTable, CommonSet.passingTypes,
				SWT.READ_ONLY);
		editors[4] = new TextCellEditor(paramTable);
		editors[5] = new ComboBoxCellEditor(paramTable, CommonSet.scopes,
				SWT.READ_ONLY);
		editors[6] = new TextCellEditor(paramTable);

		// 设置列属性
		paramTableViewer.setColumnProperties(new String[] {
				"ID", "NAME", "CLASS_TYPE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				"PASS_TYPE", "VALUE_KEY", "SCOPE", "DESCRIPTION" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
		// 设置表格单元的编辑器
		paramTableViewer.setCellEditors(editors);
		// 设置表格单元的修改器
		paramTableViewer.setCellModifier(new TableViewerCellModifier(
				paramTableViewer, this.componentModel));
	}
	
	
	private void doAdd() {
		AddParamDialog addParamDialog = new AddParamDialog(null);

		if (addParamDialog.open() == IDialogConstants.OK_ID) {
			String name = addParamDialog.getName();
			String value_key = addParamDialog.getValueKey();
			String passingType = addParamDialog.getPassingType();
			String classType = addParamDialog.getClassType();
			String scope = addParamDialog.getScope();
			String description = addParamDialog.getDescription();

			Parameter parameterVO = new Parameter();
			parameterVO.setName(name);
			parameterVO.setValueKey(value_key);
			parameterVO.setPassingType(CommonSet.convert(passingType));
			parameterVO.setClassStr(classType);
			parameterVO.setScope(Integer.parseInt(CommonSet.convert(scope)));
			parameterVO.setDescription(description);

			this.componentModel.addParameter(parameterVO);
			
			paramTableViewer.setInput(this.component.getParameterInfos());
		}
	}

	private void doEdit() {
		IStructuredSelection selection = (IStructuredSelection) paramTableViewer
				.getSelection();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ComponentFilePropertiesPart.remend"), Messages.getString("ComponentFilePropertiesPart.chooseedititem")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			EditParamDialog editParamDialog = new EditParamDialog(null);
			Parameter parameterVO = (Parameter) this.component.getParameterInfos()
					.get(paramTableViewer.getTable().getSelectionIndex());
			editParamDialog.setName(parameterVO.getName());
			editParamDialog.setClassType(parameterVO.getClassStr());
			editParamDialog.setPassingType(CommonSet.reverseConvert(parameterVO
					.getPassingType()));
			editParamDialog.setValueKey(parameterVO.getValueKey());
			editParamDialog.setScope(CommonSet.reverseConvert(parameterVO
					.getScope() + "")); //$NON-NLS-1$
			editParamDialog.setDescription(parameterVO.getDescription());
			editParamDialog.open();

			if (EditParamDialog.i == 1) {
				parameterVO.setName(editParamDialog.getName());
				parameterVO.setClassStr(editParamDialog.getClassType());
				parameterVO.setPassingType(CommonSet.convert(editParamDialog
						.getPassingType()));
				parameterVO.setValueKey(editParamDialog.getValueKey());
				parameterVO.setScope(Integer.parseInt(CommonSet.convert(editParamDialog
						.getScope())));
				parameterVO.setDescription(editParamDialog.getDescription());

				componentModel.updatepParameterValue(parameterVO);

				paramTableViewer.setInput(this.component.getParameterInfos());
			}

		}
	}

	private void doRemove() {
		ComponentModel dm = editor.getComponentModel();

		IStructuredSelection selection = (IStructuredSelection) paramTableViewer
				.getSelection();
		Parameter parameterVO = (Parameter) selection.getFirstElement();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ComponentFilePropertiesPart.remend"), Messages.getString("ComponentFilePropertiesPart.choosedeleteitem")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			if (MessageDialog
					.openConfirm(
							null,
							Messages
									.getString("ComponentFilePropertiesPart.deleteparameter"), Messages.getString("ComponentFilePropertiesPart.confirmdeleteparameter"))) { //$NON-NLS-1$ //$NON-NLS-2$
				List<?> list = (List<?>) paramTableViewer.getInput();
				dm.removeParameterNode(Integer.parseInt(parameterVO.getId()));
				list.remove(parameterVO);// 删除容器中的数据
				for (int i = 0; i < list.size(); i++) {
					Parameter parameterVO1 = (Parameter) list.get(i);
					parameterVO1.setId(i + 1 + ""); //$NON-NLS-1$
				}
				// paramTableViewer.remove(parameterVO);// 删除表格中的数据
				paramTableViewer.setInput(this.component.getParameterInfos());
			}
		}

	}

	@SuppressWarnings("unchecked") //$NON-NLS-1$
	private void doUp() {
		IStructuredSelection selection = (IStructuredSelection) paramTableViewer
				.getSelection();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ComponentFilePropertiesPart.remend"), Messages.getString("ComponentFilePropertiesPart.chooseoneitem")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			Table table = paramTableViewer.getTable();
			if (table.getItemCount() > 1) {
				if (table != null) {
					int i = table.getSelectionIndex();
					if (i > 0) {
							
						List<Parameter> parameterVolist = (List<Parameter>) paramTableViewer
						.getInput();
						Parameter TableParameterVO = (Parameter) parameterVolist.get(i);
						TableParameterVO.setId(i + ""); //$NON-NLS-1$
						parameterVolist.add(i - 1, TableParameterVO);
						((Parameter) parameterVolist.get(i)).setId(i + 1 + ""); //$NON-NLS-1$
						parameterVolist.remove(i + 1);
						paramTableViewer.setInput(parameterVolist);
						componentModel.updatepParameterValue1(parameterVolist); //方法问题处理
					}
				}
			} else {

			}
		}
	}

	@SuppressWarnings("unchecked") //$NON-NLS-1$
	private void doDown() {
		IStructuredSelection selection = (IStructuredSelection) paramTableViewer
				.getSelection();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ComponentFilePropertiesPart.remend"), Messages.getString("ComponentFilePropertiesPart.pleasechooseoneitem")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			Table table = paramTableViewer.getTable();
			if (table.getItemCount() > 1) {
				if (table != null) {
					int i = table.getSelectionIndex();
					if (i < table.getItemCount() - 1) {
						
						List<Parameter> parameterVolist = (List<Parameter>) paramTableViewer
						.getInput();
						Parameter TableParameterVO = (Parameter) parameterVolist.get(i);
						TableParameterVO.setId(i + 2 + ""); //$NON-NLS-1$
						parameterVolist.add(i + 2, TableParameterVO);
						((Parameter) parameterVolist.get(i + 1)).setId(i + 1 + ""); //$NON-NLS-1$
						parameterVolist.remove(i);
						paramTableViewer.setInput(parameterVolist);
						componentModel.updatepParameterValue1(parameterVolist);  //方法问题处理
					}
				}
			}
		}
	}

	
	@SuppressWarnings("unchecked")
	private void inital() {
		this.keyText.setText(this.component.getKey());
		this.nameText.setText(this.component.getName());
		this.classText.setText(this.component.getClassStr());
		this.descriptionText.setText(this.component.getDescription());
		this.loadstartcombo.setText("false");
		
		paramTable.removeAll();
		paramTableViewer.setInput(this.component.getParameterInfos());

	}


}
